﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;

namespace SurehealthForms.CashierLogin
{
    public partial class newDocCon : Form
    {
        string mdoctorsname;

        public newDocCon(string doctorsname)
        {
            InitializeComponent();
            mdoctorsname = doctorsname.ToUpper();
        }
   
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string filename = mdoctorsname + ".Xml";

                XmlTextWriter Writer;
                Writer = new XmlTextWriter(filename, Encoding.ASCII);
                Writer.Formatting = Formatting.Indented;
                Writer.WriteStartDocument();

                Writer.WriteStartElement("Doctor");
                Writer.WriteAttributeString("Name", mdoctorsname);
                Writer.WriteAttributeString("PatientFileName", mdoctorsname + "patients.txt");
                Writer.WriteElementString("Spendature", "0.00");
                Writer.WriteEndElement();

                Writer.WriteEndDocument();

                Writer.Close();

                StreamWriter writer = new StreamWriter(mdoctorsname + "patients.txt");
                writer.Close();


                List<string> tempDocList = new List<string>();
                StreamReader reader = new StreamReader("DoctorList.txt");
                while (reader.EndOfStream == false)
                {
                    tempDocList.Add (reader.ReadLine());
                }
                reader.Close();
                tempDocList.Add(mdoctorsname);

                StreamWriter writer2 = new StreamWriter("DoctorList.txt");
                foreach (string S in tempDocList)
                {
                    writer2.WriteLine(S);
                }

                writer2.Close();

                this.Close();
            }
            catch
            {
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void newDocCon_Load(object sender, EventArgs e)
        {

        }
    }
}
